package com.twu.biblioteca;

import com.twu.biblioteca.constant.BibliotecaConstans;
import com.twu.biblioteca.dispatcher.BibliotecaDispatcher;
import com.twu.biblioteca.exception.BookNotAvailableException;
import com.twu.biblioteca.model.Biblioteca;
import com.twu.biblioteca.view.general.CommandInputView;
import com.twu.biblioteca.view.general.StartView;

public class BibliotecaApp {

    public static void main(String[] args) {
        run();
    }

    private static void run(){
        Biblioteca biblioteca = new Biblioteca();
        biblioteca.setName(BibliotecaConstans.NAME);
        BibliotecaDispatcher dispatcher = new BibliotecaDispatcher();
        dispatcher.getController().control(biblioteca);

        display(StartView.getMSGtoDisplay(biblioteca.getName()));

        while(dispatcher.isAlive()){
            display(CommandInputView.getMSGtoDisplay());
            String request = CommandInputView.getCommand();
            String response = null;
            try {
                response = dispatcher.dispatch(request);
            } catch (BookNotAvailableException e) {
                e.printStackTrace();
            }
            display(response);
        }
    }

    private static void display(String msg) {
        System.out.println(msg);
    }
}
